<template>
    <div class="wait">
        <pullRefresh @fetchData="fetchData" v-if="NotHandoutList" :dataLoaded="dataLoaded" @refresh="refresh" @getScrollTop="getScrollTop" :scrollTop="scroll">
            <div v-for="item in NotHandoutList" :key="item.EVENT_ID">
                <div class="line-pad"></div>
                <conditionCard :info="item"  @click.native="toLink('AdDetails', item.EVENT_ID)"/>
            </div>
        </pullRefresh>
        <div v-if="this.$store.state.Administrator.NotHandoutList === undefined">
            <Alert type="warning">没有需要处理的建议信息。</Alert>
        </div>
    </div>
</template>

<script>
export default {
    components: {
        conditionCard: () => import('@/components/common/conditionCard'),
        pullRefresh: () => import('@/components/common/pullRefresh.vue')
    },
    data() {
        return {
            dataLoaded: false,
            scroll: 0
        }
    },
    computed: {
        NotHandoutList() {
            try {
                return this.$store.state.Administrator.NotHandoutList
            } catch (Error) {
                return
            }
        }
    },
    methods: {
        toLink(link, EVENT_ID) {
            sessionStorage.setItem('page', 'wait')
            sessionStorage.setItem('EVENT_ID', EVENT_ID)
            this.$router.push({
                name: link
            })
        },
        /**
         * 设置未分发列表
         * @pages 页数
         */
        async setNotHandoutList(pages) {
            let NotHandoutList = await this.$store.dispatch('getNotHandoutList', {
                page: pages
            })
            if (NotHandoutList.status === 0) {
                this.$store.commit('SET_NotHandoutList', NotHandoutList.result)
            } else {
                this.dataLoaded = true
                this.$emit('changeWadataLoaded')
            }
        },
        fetchData() {
            if (!this.dataLoaded) {
                let tempPage = this.$store.state.Administrator.waitPage
                tempPage++
                console.log(tempPage)
                this.$store.commit('SET_waitPage', tempPage)
                this.setNotHandoutList(this.$store.state.Administrator.waitPage)
            }
        },
        refresh() {
            this.$store.commit('SET_NotHandoutList', null)
            this.dataLoaded = false
            this.$store.commit('SET_waitPage', 1)
            this.setNotHandoutList(1)
        },
        getScrollTop(scrollTop) {
            this.scroll = scrollTop
        }
    },
    created() {
        console.log('进入')
        this.scroll = this.$store.state.Administrator.waitScroll
    },
    destroyed() {
        console.log('切换')
        this.$store.commit('SET_waitScroll', this.scroll)
    }
}
</script>

<style lang="less">
    .wait{
        height: 100%;
        .pullRefresh{
          background-color:#f8f8f8 !important;
        }
    }
</style>
